<template>
  <div :class="isSubPage ? '' : 'app-container'">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item prop="qry_meetID" v-if="!isSubPage">所属会议
          <el-input v-model="queryParam.qry_dispmeetID" :disabled="true" class="tl-ref-selector" style="width:200px">
            <el-button slot="append" type="primary" icon="el-icon-search" @click="openMeetManageRefDialog"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="qry_title">任务主题
          <el-input v-model="queryParam.qry_title" placeholder="请输入任务主题" style="padding-left:5px"></el-input>
        </el-form-item>
        <el-form-item prop="qry_state">任务状态
          <el-select v-model="queryParam.qry_state" filterable clearable style="padding-left:5px">
            <el-option v-for="item in codeModelFromOA.stateList" :key="'taskState' + item.code" :label="item.name" :value="item.code" />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="isSubPage ? '300px' : tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center" header-align="center"></el-table-column>
        <el-table-column prop="taskmaintitle" label="任务主题" min-width="150px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="handleusername" label="责任人" width="170px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="enddate" label="截止日期" width="120px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="120px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispisdelay" label="是否延期" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="initiatedate" label="发起日期" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="tasknumber" label="任务编号" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="initiatorname" label="任务发起人" width="120px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="username" label="记录人" width="170px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="taskdescription" label="任务描述" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="evaluationlev" label="评价等级" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="latestphase" label="最新阶段" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column label="操作" width="110px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row)">查看</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete"  @click.native="showDropDialog(scope.row)" :disabled="scope.row.state === 2" v-if="!isReadOnly">终止</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm"  @refresh="doRefresh" :codeModelFromOA="codeModelFromOA" :isFromMenu="!isSubPage" :sourceMeetID="sourceMeetID"></tl-edit>
      <tl-ref-meet-manage ref="meetManageRef" :singleSelect="true" @confirm="getMeetManageRefData"></tl-ref-meet-manage>
      <tl-drop ref="dropRef" @refresh="doRefresh"></tl-drop>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from "@tapui/mixins/mixin_list"
/** 子组件 */
import tlEdit from "./edit"
import tlRefMeetManage from "../meetManage/refList"
import tlDrop from "./drop"
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from "@tapui/utils/http"
export default {
  name: "taskManage",
  mixins: [mixin_list],
  components: { tlEdit, tlRefMeetManage, tlDrop },
  data() {
    return {
      description: "任务管理-列表查询",
      urlPrefix: "/meet/taskManage/",
      url: {
        dataCodeList: "/meet/taskManage/dataCodeList"
      },
      isQueryOnCreated: false,
      // 查询条件
      queryParam: {
        sourceType: "meetSearch"
      },
      // 存储所有的数据
      // allTasks: [],
      // 分页信息
      pageInfo: {
        currentPage: 1, // 当前页面
        pageSize: 5, // 每页记录数
        pageSizes: ["5", "10", "50", "100"],
        totalCount: 0 // 总数
      },
      // 排序参数
      sorterInfo: {
        sidx: "enddate",
        sord: "asc"
      },
      rowDbClickActionType: "view",
      codeModelFromOA: {}
    }
  },
  props: {
    isSubPage: {
      type: Boolean,
      default: false
    },
    sourceType: {
      type: String,
      default: "meetCreate"
    },
    sourceMeetID: {
      type: [Number, String],
      default: ""
    },
    isReadOnly: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    /** 加载数据之前 */
    beforeLoadData() {
      if (this.isSubPage) {
        this.queryParam.qry_meetID = this.sourceMeetID
      } else {
        if (!this.queryParam.qry_meetID) {
          this.$tap.alert("请选择所属会议", "warning")
          return false
        }
      }
      this.queryParam = {
        ...this.queryParam,
        sourceType: this.sourceType
      }
      return true
    },
    /** 加载数据之后 */
    // afterLoadData() {
    //   this.allTasks = [...this.datas]
    //   this.pageInfo.pageSize = 5
    //   this.doChangeIndex(1)
    // },
    /** 打开会议管理参照 */
    openMeetManageRefDialog() {
      this.$refs.meetManageRef.visible = true
    },
    /** 获取会议管理参数数据 */
    getMeetManageRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.queryParam, "qry_meetID", selectionRow.id)
      this.$set(this.queryParam, "qry_dispmeetID", selectionRow.name)
    },
    /** 打开详情对话框实现*/
    openViewDialog(editForm, task) {
      if (!this.beforeOpenViewDialog(editForm, task.id)) {
        return
      }
      this.$refs[editForm].id = task.id
      this.$refs[editForm].model = task
      this.$refs[editForm].isAdd = false
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = true
      this.$nextTick(() => {
        this.afterOpenViewDialog(editForm, task.id)
      })
      let that = this
      setTimeout(() => {
        that.clickRowkey = task.id
      }, 100)
    },
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      if (this.rowDbClickActionType === "edit") {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (this.checkPermission(this.editPermission)) {
            this.openEditDialog("editForm", row)
          } else {
            this.openViewDialog("editForm", row)
          }
        } else {
          this.openEditDialog("editForm", row)
        }
      } else if (this.rowDbClickActionType === "view") {
        this.openViewDialog("editForm", row)
      }
    },
    /** 查询编码列表 */
    queryDataCodeList() {
      if (this.url.dataCodeList) {
        getAction(this.url.dataCodeList, {}).then((res) => {
          if (res.success) {
            this.codeModelFromOA = res.result
          } else {
            this.$tap.alert(res.message, "warning")
          }
        })
      }
    },
    /** 每页大小改变*/
    // doChangeSize(val) {
    //   if (this.pageInfo.pageSize !== val) {
    //     this.pageInfo.pageSize = val
    //     this.doChangeIndex(1)
    //   }
    // },
    /** 页面跳转 */
    // doChangeIndex(val) {
    //   this.pageInfo.currentPage = val
    //   const pageSize = this.pageInfo.pageSize
    //   const start = (val - 1) * pageSize
    //   const end = val * pageSize
    //   this.datas = this.allTasks.slice(start, end)
    // },
    showDropDialog(taskObj) {
      this.$refs.dropRef.visible = true
      this.$nextTick(() => {
        this.$refs.dropRef.taskObj = taskObj
      })
    }
  },
  /** 组件创建 */
  created() {
    // if (!this.isSubPage) {
    //   this.loadData({})
    // }
  },
  mounted() {
    // 修改为立即查询
    this.queryDataCodeList()
    // this.$nextTick(() => {
    //   // 查询编码列表
    //   const that = this
    //   setTimeout(function() {
    //     that.queryDataCodeList()
    //   }, 2000)
    // })
  }
}
</script>

<style scoped></style>
